package com.example.demo_flow

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.flatMapMerge
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.zip
import kotlinx.coroutines.runBlocking
import java.util.concurrent.Flow

/**
 * @author yaotianxue
 * @description
 * @date 2025/1/9
zip：处理接口并行关系，将多个接口请求返回数据合并在一起，首页数据多个接口最终展示在一个recyclerview中

 */
fun main() {

    runBlocking {
        sendRealtimeWeatherRequest()
            .zip(sendSevenDaysWeatherRequest()){realtimeWeather, sevenDaysWeather ->
                var list = mutableListOf<String>()
                list.add(realtimeWeather)
                list.add(sevenDaysWeather)
                list //当作结果合并一起
            }.collect{list->
                println(list)

            }
    }
}


fun sendRealtimeWeatherRequest()= flow {
    emit("今天的天气")
}

fun sendSevenDaysWeatherRequest() = flow {
    emit("未来7天的天气")
}